<?php 
/*
 * This filter convert simple array to tree array
 * and sort it
 *  
 */
class Zen_Filter_Declension implements Zend_Filter_Interface
{
    
	private $_word;
	
	private $_count=0;
	
	private $_type=1;
	
    public function filter($value){
    	$this->_word = $value;
    	$type = $this->_type;
    	$method = "_decline" . $type;
    	return $this->$method();
    }
    
    private function _decline1() {
    	$word = $this->_word;
    	$count = $this->_count;
    	$ending = "";
		switch (true) {
			case ( 0 == $count ) : { $ending = 'ов';  break;}
			case ( 1 == $count ) : { $ending = '';  break;}
			case ( 2 <= $count && $count <= 4 ) : { $ending = 'a';  break;}
			case ( 5 <= $count && $count <= 20 ) : { $ending = 'ов';  break;}
			case ( 0 == ($count % 10) ) : { $ending = 'ов';  break;}
			case ( 1 == ($count % 10) ) : { $ending = '';  break;}
			case ( 2 <= ($count % 10) && ($count % 10) <= 4 ) : { $ending = 'a';  break;}
			case ( 5 <= ($count % 10) && ($count % 10) <= 9 ) : { $ending = 'ов';  break;}
			default: {}
		}
    	return $word . $ending;
    }
    
	private function _decline2() {
    	$word = $this->_word;
    	$count = $this->_count;
    	$ending = "";
		switch (true) {
			case ( 0 == $count ) : { $ending = 'ей';  break;}
			case ( 1 == $count ) : { $ending = 'ь';  break;}
			case ( 2 <= $count && $count <= 4 ) : { $ending = 'и';  break;}
			case ( 5 <= $count && $count <= 20 ) : { $ending = 'ей';  break;}
			case ( 0 == ($count % 10) ) : { $ending = 'ей';  break;}
			case ( 1 == ($count % 10) ) : { $ending = 'ь';  break;}
			case ( 2 <= ($count % 10) && ($count % 10) <= 4 ) : { $ending = 'и';  break;}
			case ( 5 <= ($count % 10) && ($count % 10) <= 9 ) : { $ending = 'ей';  break;}
			default: {}
		}
    	return $word . $ending;
    }
    
	public function setType($type) {
    	$this->_type = $type;
    	return $this;
    }
    
    public function setCount($count) {
    	$this->_count = $count;
    	return $this;
    }
}